import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDDrop {
	/**编号(主键)*/
	id,
	/**掉落组DropGroup.id*/
	dropid,
	/**活动标识--1翻倍标识--2额外掉落标识*/
	activityTag,
	/**概率下限--符号<=*/
	rateLow,
	/**概率上限（万分比）--符号<=*/
	rateUp,
	/**物品类型--1.资源点2.道具3.装备4.符文5.魔纹6.宠物99.dropset数组*/
	itemType,
	/**装备等级*/
	equipmentLevel,
	/**物品id*/
	itemid,
	/**数量*/
	num,
	/**分组用标志是否为第一个单位*/
	sign,

	/**枚举数量*/
	EnumCount
}



export class CDDrop{
	/**编号(主键)*/
	public id: number;
	/**掉落组DropGroup.id*/
	public dropid: number;
	/**活动标识--1翻倍标识--2额外掉落标识*/
	public activityTag: number;
	/**概率下限--符号<=*/
	public rateLow: number;
	/**概率上限（万分比）--符号<=*/
	public rateUp: number;
	/**物品类型--1.资源点2.道具3.装备4.符文5.魔纹6.宠物99.dropset数组*/
	public itemType: number;
	/**装备等级*/
	public equipmentLevel: number;
	/**物品id*/
	public itemid: number;
	/**数量*/
	public num: number;
	/**分组用标志是否为第一个单位*/
	public sign: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDDrop.id: return this.id;
			case E_CDDrop.dropid: return this.dropid;
			case E_CDDrop.activityTag: return this.activityTag;
			case E_CDDrop.rateLow: return this.rateLow;
			case E_CDDrop.rateUp: return this.rateUp;
			case E_CDDrop.itemType: return this.itemType;
			case E_CDDrop.equipmentLevel: return this.equipmentLevel;
			case E_CDDrop.itemid: return this.itemid;
			case E_CDDrop.num: return this.num;
			case E_CDDrop.sign: return this.sign;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDDrop.id: this.id = v; break;
			case E_CDDrop.dropid: this.dropid = v; break;
			case E_CDDrop.activityTag: this.activityTag = v; break;
			case E_CDDrop.rateLow: this.rateLow = v; break;
			case E_CDDrop.rateUp: this.rateUp = v; break;
			case E_CDDrop.itemType: this.itemType = v; break;
			case E_CDDrop.equipmentLevel: this.equipmentLevel = v; break;
			case E_CDDrop.itemid: this.itemid = v; break;
			case E_CDDrop.num: this.num = v; break;
			case E_CDDrop.sign: this.sign = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDDrop> = new HashMap<number, CDDrop>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDDrop[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDDrop();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].dropid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].activityTag = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rateLow = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rateUp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].equipmentLevel = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].num = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].sign = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDDrop{
		return this.datas ? this.datas.get(id) : null;
	}
}
